﻿//-----------------------------------------------------------------------
// <copyright file="AdminViewModel.cs" company="FER">
//     Copyright (c) All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System.Collections.ObjectModel;
using NMBP.Models;

namespace NMBP.View.ViewModel
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.IO;
    using System.Linq;
    using DAL;
    using GalaSoft.MvvmLight;
    using GalaSoft.MvvmLight.Command;
    using GalaSoft.MvvmLight.Messaging;
    using Models.Converters;
    using Validators;
    using ViewModels.Dialogs;

    /// <summary>
    /// Represents view model for Adminwindow
    /// </summary>
    public class AdminViewModel : ViewModelBase
    {
        #region Bindable fields

        #region SelectProduct
        /// <summary>
        /// Gets or sets collection of products in datagrid
        /// </summary>
        private ObservableCollection<Product> dataGridProducts;

        /// <summary>
        /// Gets or sets selected product in datagrid
        /// </summary>
        private Product selectedProduct;

        /// <summary>
        /// Gets or sets selected products description
        /// </summary>
        private string selectedDescription;

        /// <summary>
        /// Gets or sets selected products in stock
        /// </summary>
        private long selectedStock;

        /// <summary>
        /// Gets or sets selected products price
        /// </summary>
        private float selectedPrice;
        #endregion

        #region AddProduct

        /// <summary>
        /// Gets or sets new description
        /// </summary>
        private string newDescription;

        /// <summary>
        /// Gets or sets new stock
        /// </summary>
        private long newStock;

        /// <summary>
        /// Gets or sets new price
        /// </summary>
        private float newPrice;

        /// <summary>
        /// Gets or sets new picture path
        /// </summary>
        private string newPicturePath;

        #endregion

        #region Person

        /// <summary>
        /// Gets or sets list of persons
        /// </summary>
        private ObservableCollection<Person> dataGridPersons;

        /// <summary>
        /// Gets or sets selected person
        /// </summary>
        private Person selectedPerson;

        #endregion

        #region Department
        /// <summary>
        /// Gets or sets selected department
        /// </summary>
        private Department selectedDepartment;

        /// <summary>
        /// Gets or sets data grid departments
        /// </summary>
        private ObservableCollection<Department> dataGridDepartments;

        /// <summary>
        /// Gets or sets selected department name
        /// </summary>
        private string selectedDepartmentName;

        /// <summary>
        /// Gets or sets all workers
        /// </summary>
        private ObservableCollection<Worker> allWorkers;

        /// <summary>
        /// GEts or sets new department name
        /// </summary>
        private string newDepartmentName;

        /// <summary>
        /// Gets or sets collection of workers in department
        /// </summary>
        private ObservableCollection<Worker> workersInDepartment;
        #endregion

        #region Supplier
        
        /// <summary>
        /// Gets or sets selected supplier
        /// </summary>
        private Supplier selectedSupplier;

        /// <summary>
        /// Gets or sets list of available suppliers
        /// </summary>
        private ObservableCollection<Supplier> dataGridSupplier;

        /// <summary>
        /// Gets or sets selected supplier name
        /// </summary>
        private string selectedSupplierName;

        /// <summary>
        /// Gets or sets selected supplier contact
        /// </summary>
        private string selectedSupplierContact;

        /// <summary>
        /// Gets or sets selected supplier acc num
        /// </summary>
        private string selectedSupplierAccNum;

        /// <summary>
        /// Gets or sets new supplier name
        /// </summary>
        private string newSupplierName;

        /// <summary>
        /// Gets or sets new supplier contact
        /// </summary>
        private string newSupplierContact;

        /// <summary>
        /// Gets or sets new supplier acc num
        /// </summary>
        private string newSupplierAccNum;

        #endregion

        #endregion

        /// <summary>
        /// Action raised when view model needs to be initialized
        /// </summary>
        private readonly Action<Worker> initViewModel;

        /// <summary>
        /// recieved worker
        /// </summary>
        private Worker recievedWorker;

        /// <summary>
        /// Initializes a new instance of the AdminViewModel class
        /// </summary>
        public AdminViewModel()
        {
            this.initViewModel = new Action<Worker>(this.InitializeViewModel);
            Messenger.Default.Register<Worker>(this, "InitializeAdmin", this.initViewModel);

            #region Product commands
            this.UpdateProduct = new RelayCommand( ()=>
                                                       {
                                                           if (this.selectedProduct == null)
                                                           {
                                                               this.DialogService.ShowMessage("Nije označen proizvod!", MessageType.ERROR);
                                                               return;
                                                           }
                                                           var updateProduct = this.selectedProduct;

                                                           this.selectedProduct.Description = this.SelectedDescription;
                                                           this.selectedProduct.SetStockValue(this.SelectedStock);
                                                           this.selectedProduct.Price = this.SelectedPrice;

                                                           this.DataGridProducts.Remove(this.selectedProduct);
                                                           this.DataGridProducts.Add(updateProduct);
                                                           this.DbFacade.SaveProducts(this.DataGridProducts.ToList());
                                                       } );

            this.DeleteProduct = new RelayCommand(() =>
                                                      {
                                                          if (this.selectedProduct == null)
                                                          {
                                                              this.DialogService.ShowMessage("Nije označen proizvod!", MessageType.ERROR);
                                                              return;
                                                          }

                                                          if (this.DialogService.DoesUserConfirms("Želite li stvarno obrisati proizvod?"))
                                                          {
                                                              this.DataGridProducts.Remove(this.SelectedProduct);
                                                              this.DbFacade.SaveProducts(this.DataGridProducts.ToList());
                                                          }
                                                      });

            this.AddNewProduct = new RelayCommand(() =>
                                                      {
                                                          try
                                                          {
                                                              var image = Image.FromFile(this.newPicturePath);
                                                              var newProduct = new Product
                                                              {
                                                                  Description = this.newDescription,
                                                                  InStock = this.newStock,
                                                                  InCart = false,
                                                                  Price = this.newPrice,
                                                                  Image = MyImageConverter.ImageToByteArray(image)
                                                              };

                                                              if (!ProductValidator.ValidateProduct(newProduct))
                                                              {
                                                                  this.DialogService.ShowMessage(
                                                                      "Proizvod neispravno zadan. Ne dodajem novi proizvod.",
                                                                      MessageType.ERROR);
                                                                  return;
                                                              }

                                                              if (this.DataGridProducts.FirstOrDefault(p => p.Description == this.newDescription) != null)
                                                              {
                                                                  this.DialogService.ShowMessage(
                                                                      "Proizvod sa istim opisom već postoji.",
                                                                      MessageType.ERROR);
                                                                  return;
                                                              }

                                                              this.DataGridProducts.Add(newProduct);
                                                              this.DbFacade.SaveProducts(this.DataGridProducts.ToList());
                                                          }
                                                          catch (FileNotFoundException)
                                                          {
                                                              this.DialogService.ShowMessage("Slika ne postoji. Učitavanje neuspješno.", MessageType.ERROR);
                                                              return;
                                                          }
                                                          catch (ArgumentNullException)
                                                          {
                                                              this.DialogService.ShowMessage("Neispravno zadana slika. Učitavanje neuspješno.", MessageType.ERROR);
                                                              return;
                                                          }
                                                      });
            this.AddPicture = new RelayCommand(()=>
                                                   {
                                                       // Create OpenFileDialog
                                                       Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

                                                       // Set filter for file extension and default file extension
                                                       dlg.DefaultExt = ".jpg";
                                                       dlg.Filter = "Slike (.jpg)|*.jpg";

                                                       // Display OpenFileDialog by calling ShowDialog method
                                                       Nullable<bool> result = dlg.ShowDialog();

                                                       // Get the selected file name and display in a TextBox
                                                       if (result == true)
                                                       {
                                                           // Open document
                                                           string filename = dlg.FileName;
                                                           this.NewPicturePath = filename;
                                                       }
                                                   });
            #endregion

            #region Person commands

            this.AddEditWorker = new RelayCommand(() => Messenger.Default.Send(this.recievedWorker, "OpenEditWorkerWindow"));
            this.AddEditCustomer = new RelayCommand(() => Messenger.Default.Send(this.recievedWorker, "OpenEditCustomerWindow"));

            this.DeletePerson = new RelayCommand( () =>
                                                      {
                                                          if (this.DialogService.DoesUserConfirms("Želite li stvarno obrisati osobu?"))
                                                          {
                                                              this.DbFacade.DeletePerson(this.selectedPerson);
                                                              this.DataGridPersons.Remove(this.selectedPerson);
                                                          }
                                                      });

            #endregion

            #region Department commands

            this.UpdateDept = new RelayCommand(() =>
                                                   {
                                                       if (this.SelectedDepartment == null)
                                                       {
                                                           this.DialogService.ShowMessage("Nije označen odjel.", MessageType.ERROR);
                                                           return;
                                                       }

                                                       var updateDept = this.selectedDepartment;

                                                       this.selectedDepartment.Name = this.selectedDepartmentName;

                                                       this.DataGridDepartments.Remove(this.selectedDepartment);
                                                       this.DataGridDepartments.Add(updateDept);
                                                       this.DbFacade.SaveDepartments(this.DataGridDepartments.ToList());
                                                   });

            this.DelDept = new RelayCommand(() =>
                                                {
                                                    if (this.selectedDepartment == null)
                                                    {
                                                        this.DialogService.ShowMessage("Nije označen odjel!", MessageType.ERROR);
                                                        return;
                                                    }

                                                    if (
                                                        this.DialogService.DoesUserConfirms("Želite li stvarno obrisati odjel?"))
                                                    {
                                                        this.DataGridDepartments.Remove(this.SelectedDepartment);
                                                        this.DbFacade.SaveDepartments(this.DataGridDepartments.ToList());
                                                    }
                                                });

            this.NewDept = new RelayCommand(() =>
                                                {
                                                    var department = new Department
                                                    {
                                                        Name = this.newDepartmentName,
                                                    };

                                                    if (this.DataGridDepartments.FirstOrDefault(p => p.Name == this.newDepartmentName) != null)
                                                    {
                                                        this.DialogService.ShowMessage("Odjel sa istim imenom već postoji.", MessageType.ERROR);
                                                        return;
                                                    }

                                                    this.DataGridDepartments.Add(department);
                                                    this.DbFacade.SaveDepartments(this.DataGridDepartments.ToList());
                                                });
            #endregion

            #region Supplier commands

            this.UpdateSupplier = new RelayCommand(() =>
                                                       {
                                                           if (this.selectedSupplier == null)
                                                           {
                                                               this.DialogService.ShowMessage(
                                                                   "Nije označen dobavljač!", MessageType.ERROR);
                                                               return;
                                                           }
                                                           var updateSupplier = this.selectedSupplier;

                                                           this.selectedSupplier.Name = this.SelectedSupplierName;
                                                           this.selectedSupplier.Contact = this.SelectedSupplierContact;
                                                           this.selectedSupplier.AccountNumber =
                                                               this.SelectedSupplierAccNum;

                                                           this.DataGridSupplier.Remove(this.selectedSupplier);
                                                           this.DataGridSupplier.Add(updateSupplier);
                                                           this.DbFacade.SaveSuppliers(this.DataGridSupplier.ToList());
                                                       });

            this.DeleteSupplier = new RelayCommand(() =>
                                                       {
                                                           if (this.selectedSupplier == null)
                                                           {
                                                               this.DialogService.ShowMessage(
                                                                   "Nije označen dobavljač!", MessageType.ERROR);
                                                               return;
                                                           }

                                                           if (
                                                               this.DialogService.DoesUserConfirms(
                                                                   "Želite li stvarno obrisati dobavljača?"))
                                                           {
                                                               this.DataGridSupplier.Remove(this.SelectedSupplier);
                                                               this.DbFacade.SaveSuppliers(
                                                                   this.DataGridSupplier.ToList());
                                                           }
                                                       });

            this.NewSupplier = new RelayCommand(()=>
                                                    {
                                                        var newSupplier = new Supplier
                                                                              {
                                                                                  Name = this.NewSupplierName,
                                                                                  Contact = this.NewSupplierContact,
                                                                                  AccountNumber = this.NewSupplierAccNum,
                                                                                  IsActive = true
                                                                              };

                                                        if (!SupplierValidator.IsSupplierValid(newSupplier))
                                                        {
                                                            this.DialogService.ShowMessage("Neispravni podaci za dobavljača!", MessageType.ERROR);
                                                            return;
                                                        }

                                                        if (this.DataGridSupplier.FirstOrDefault(p => p.Name == this.newSupplierName) != null)
                                                        {
                                                            this.DialogService.ShowMessage("Dobavljač sa istim imenom već postoji.", MessageType.ERROR);
                                                            return;
                                                        }

                                                        this.DataGridSupplier.Add(newSupplier);
                                                        this.DbFacade.SaveSuppliers(this.DataGridSupplier.ToList());
                                                    });
            #endregion
        }

        #region Bindable properties

        /// <summary>
        /// Gets or sets instance of db facade
        /// </summary>
        IDbFacade DbFacade { get; set; }

        /// <summary>
        /// Gets or sets instance of dialog service
        /// </summary>
        IDialogService DialogService { get; set; }

        #region Commands

        #region Product commands
        /// <summary>
        /// Gets command executed when update product button is clicked
        /// </summary>
        public RelayCommand UpdateProduct { get; private set; }

        /// <summary>
        /// Gets command executed when delete product button is clicked
        /// </summary>
        public RelayCommand DeleteProduct { get; private set; }

        /// <summary>
        /// Gets command executed when add new product button is clicked
        /// </summary>
        public RelayCommand AddNewProduct { get; private set; }

        /// <summary>
        /// Gets a command executed when add picture button is clicked
        /// </summary>
        public RelayCommand AddPicture { get; private set; }
        #endregion

        #region Person Commands
        /// <summary>
        /// Gets the command executed when edit person button is clicked
        /// </summary>
        public RelayCommand AddEditCustomer { get; private set; }

        /// <summary>
        /// Gets the command executed when edit person button is clicked
        /// </summary>
        public RelayCommand AddEditWorker { get; private set; }

        /// <summary>
        /// Gets the command executed when delete person button is clicked
        /// </summary>
        public RelayCommand DeletePerson { get; private set; }
        #endregion

        #region Department commands
        /// <summary>
        /// Gets the command executed when update department button is clicked
        /// </summary>
        public RelayCommand UpdateDept { get; private set; }

        /// <summary>
        /// Gets the command executed when del dept button is clicked
        /// </summary>
        public RelayCommand DelDept { get; private set; }
        
        /// <summary>
        /// Gets the command executed when new dept button is clicked
        /// </summary>
        public RelayCommand NewDept { get; private set; }
        #endregion

        #region Supplier commands
        /// <summary>
        /// Gets the command raised when update supplier button is clicked
        /// </summary>
        public RelayCommand UpdateSupplier { get; private set; }

        /// <summary>
        /// Gets the command raised when delete supplier button is clicked
        /// </summary>
        public RelayCommand DeleteSupplier { get; private set; }

        /// <summary>
        /// Gets the command raised when add new supplier button is clicked
        /// </summary>
        public RelayCommand NewSupplier { get; private set; }

        #endregion

        #endregion

        #region SelectProduct
        /// <summary>
        /// Gets or sets collection of products in datagrid
        /// </summary>
        public ObservableCollection<Product> DataGridProducts
        {
            get
            {
                return this.dataGridProducts;
            }

            set
            {
                this.dataGridProducts = value;
                this.RaisePropertyChanged("DataGridProducts");
            }
        }

        /// <summary>
        /// Gets or sets selected product in datagrid
        /// </summary>
        public Product SelectedProduct
        {
            get
            {
                return this.selectedProduct;
            }

            set
            {
                this.selectedProduct = value;
                if (value != null)
                {
                    this.LoadValuesForSelectedProduct();
                }

                this.RaisePropertyChanged("SelectedProduct");
            }
        }

        /// <summary>
        /// Gets or sets selected products description
        /// </summary>
        public string SelectedDescription
        {
            get
            {
                return this.selectedDescription;
            }

            set
            {
                this.selectedDescription = value;
                this.RaisePropertyChanged("SelectedDescription");
            }
        }

        /// <summary>
        /// Gets or sets selected products in stock
        /// </summary>
        public long SelectedStock
        {
            get
            {
                return this.selectedStock;
            }

            set
            {
                this.selectedStock = value;
                this.RaisePropertyChanged("SelectedStock");
            }
        }

        /// <summary>
        /// Gets or sets selected products price
        /// </summary>
        public float SelectedPrice
        {
            get
            {
                return this.selectedPrice;
            }

            set
            {
                this.selectedPrice = value;
                this.RaisePropertyChanged("SelectedPrice");
            }
        }
        #endregion

        #region AddProduct
        /// <summary>
        /// Gets or sets new description
        /// </summary>
        public string NewDescription
        {
            get
            {
                return this.newDescription;
            }

            set
            {
                this.newDescription = value;
                this.RaisePropertyChanged("NewDescription");
            }
        }

        /// <summary>
        /// Gets or sets new stock
        /// </summary>
        public long NewStock
        {
            get
            {
                return this.newStock;
            }

            set
            {
                this.newStock = value;
                this.RaisePropertyChanged("NewStock");
            }
        }

        /// <summary>
        /// Gets or sets new price
        /// </summary>
        public float NewPrice
        {
            get
            {
                return this.newPrice;
            }

            set
            {
                this.newPrice = value;
                this.RaisePropertyChanged("NewPrice");
            }
        }

        /// <summary>
        /// Gets or sets new picture path
        /// </summary>
        public string NewPicturePath
        {
            get
            {
                return this.newPicturePath;
            }

            set
            {
                this.newPicturePath = value;
                this.RaisePropertyChanged("NewPicturePath");
            }
        }

        #endregion

        #region Person

        /// <summary>
        /// Gets or sets list of persons
        /// </summary>
        public ObservableCollection<Person> DataGridPersons
        {
            get
            {
                return this.dataGridPersons;
            }

            set
            {
                this.dataGridPersons = value;
                this.RaisePropertyChanged("DataGridPersons");
            }
        }

        /// <summary>
        /// Gets or sets selected person
        /// </summary>
        public Person SelectedPerson
        {
            get
            {
                return this.selectedPerson;
            }

            set
            {
                this.selectedPerson = value;
                this.RaisePropertyChanged("SelectedPerson");
            }
        }
        #endregion

        #region Department properties
        /// <summary>
        /// Gets or sets selected department
        /// </summary>
        public Department SelectedDepartment
        {
            get
            {
                return this.selectedDepartment;
            }

            set
            {
                this.selectedDepartment = value;
                if (value != null)
                {
                    this.LoadValuesForSelectedDepartment();
                }
                this.RaisePropertyChanged("SelectedDepartment");
            }
        }

        /// <summary>
        /// Gets or sets data grid departments
        /// </summary>
        public ObservableCollection<Department> DataGridDepartments
        {
            get
            {
                return this.dataGridDepartments;
            }

            set
            {
                this.dataGridDepartments = value;
                this.RaisePropertyChanged("DataGridDepartments");
            }
        }

        /// <summary>
        /// Gets or sets selected department name
        /// </summary>
        public string SelectedDepartmentName
        {
            get
            {
                return this.selectedDepartmentName;
            }

            set
            {
                this.selectedDepartmentName = value;
                this.RaisePropertyChanged("SelectedDepartmentName");
            }
        }

        /// <summary>
        /// Gets or sets all workers
        /// </summary>
        public ObservableCollection<Worker> AllWorkers
        {
            get
            {
                return this.allWorkers;
            }

            set
            {
                this.allWorkers = value;
                this.RaisePropertyChanged("AllWorkers");
            }
        }

        /// <summary>
        /// GEts or sets new department name
        /// </summary>
        public string NewDepartmentName
        {
            get
            {
                return this.newDepartmentName;
            }

            set
            {
                this.newDepartmentName = value;
                this.RaisePropertyChanged("NewDepartmentName");
            }
        }

        /// <summary>
        /// Gets or sets collection of workers in department
        /// </summary>
        public ObservableCollection<Worker> WorkersInDepartment
        {
            get
            {
                return this.workersInDepartment;
            }

            set
            {
                this.workersInDepartment = value;
                this.RaisePropertyChanged("WorkersInDepartment");
            }
        }

        #endregion

        #region Suppliers
        /// <summary>
        /// Gets or sets selected supplier
        /// </summary>
        public Supplier SelectedSupplier
        {
            get
            {
                return this.selectedSupplier;
            }

            set
            {
                this.selectedSupplier = value;
                if (value != null)
                {
                    this.LoadValuesForSelectedSupplier();
                }
                this.RaisePropertyChanged("SelectedSupplier");
            }
        }

        /// <summary>
        /// Gets or sets list of available suppliers
        /// </summary>
        public ObservableCollection<Supplier> DataGridSupplier
        {
            get
            {
                return this.dataGridSupplier;
            }

            set
            {
                this.dataGridSupplier = value;
                this.RaisePropertyChanged("DataGridSupplier");
            }
        }

        /// <summary>
        /// Gets or sets selected supplier name
        /// </summary>
        public string SelectedSupplierName
        {
            get
            {
                return this.selectedSupplierName;
            }
            set
            {
                this.selectedSupplierName = value;
                this.RaisePropertyChanged("SelectedSupplierName");
            }
        }

        /// <summary>
        /// Gets or sets selected supplier contact
        /// </summary>
        public string SelectedSupplierContact
        {
            get
            {
                return this.selectedSupplierContact;
            }

            set
            {
                this.selectedSupplierContact = value;
                this.RaisePropertyChanged("SelectedSupplierContact");
            }
        }

        /// <summary>
        /// Gets or sets selected supplier acc num
        /// </summary>
        public string SelectedSupplierAccNum
        {
            get
            {
                return this.selectedSupplierAccNum;
            }

            set
            {
                this.selectedSupplierAccNum = value;
                this.RaisePropertyChanged("SelectedSupplierAccNum");
            }
        }

        /// <summary>
        /// Gets or sets new supplier name
        /// </summary>
        public string NewSupplierName
        {
            get
            {
                return this.newSupplierName;
            }

            set
            {
                this.newSupplierName = value;
                this.RaisePropertyChanged("NewSupplierName");
            }
        }

        /// <summary>
        /// Gets or sets new supplier contact
        /// </summary>
        public string NewSupplierContact
        {
            get
            {
                return this.newSupplierContact;
            }

            set
            {
                this.newSupplierContact = value;
                this.RaisePropertyChanged("NewSupplierContact");
            }
        }

        /// <summary>
        /// Gets or sets new supplier acc num
        /// </summary>
        public string NewSupplierAccNum
        {
            get
            {
                return this.newSupplierAccNum;
            }

            set
            {
                this.newSupplierAccNum = value;
                this.RaisePropertyChanged("NewSupplierAccNum");
            }
        }

        #endregion

        #endregion

        /// <summary>
        /// Initializes view model with worker class
        /// </summary>
        /// <param name="worker"></param>
        private void InitializeViewModel(Worker worker)
        {
            if (this.DbFacade == null)
            {
                this.DbFacade = new DbFacade();
            }
            this.recievedWorker = worker;
            this.DialogService = new DialogService();

            this.DataGridProducts = new ObservableCollection<Product>();
            this.DataGridPersons = new ObservableCollection<Person>();
            this.DataGridDepartments = new ObservableCollection<Department>();
            this.DataGridSupplier = new ObservableCollection<Supplier>();

            this.LoadProductsToDataGrid();
            this.LoadPersonsToDataGrid();
            this.LoadDepartmentsToDataGrid();
            this.LoadSuppliersToDataGrid();
        }

        /// <summary>
        /// Loads products from database to datagrid
        /// </summary>
        private void LoadProductsToDataGrid()
        {
            var products = this.DbFacade.GetProducts();
            foreach (var product in products)
            {
                this.DataGridProducts.Add(product);
            }
        }

        /// <summary>
        /// Loads persons from database to datagrid
        /// </summary>
        private void LoadPersonsToDataGrid()
        {
            var persons = this.DbFacade.GetPersons();
            foreach (var person in persons)
            {
                this.DataGridPersons.Add(person);
            }
        }

        /// <summary>
        /// Loads departments to datagrid
        /// </summary>
        private void LoadDepartmentsToDataGrid()
        {
            var departments = this.DbFacade.GetDepartments();
            foreach (var department in departments)
            {
                  this.DataGridDepartments.Add(department);
            }
        }

        /// <summary>
        /// Load suppliers to datagrid
        /// </summary>
        private void LoadSuppliersToDataGrid()
        {
            var suppliers = this.DbFacade.GetSuppliers();
            foreach (var supplier in suppliers)
            {
                this.DataGridSupplier.Add(supplier);
            }
        }

        /// <summary>
        /// Loads values for selected product
        /// </summary>
        private void LoadValuesForSelectedProduct()
        {
            this.SelectedDescription = this.selectedProduct.Description;
            this.SelectedStock = this.selectedProduct.InStock;
            this.SelectedPrice = this.selectedProduct.Price;
        }

        /// <summary>
        /// Loads values for selected department
        /// </summary>
        private void LoadValuesForSelectedDepartment()
        {
            this.AllWorkers = new ObservableCollection<Worker>();
            var workers = this.DbFacade.GetWorkers();
            foreach (var worker in workers)
            {
                this.AllWorkers.Add(worker);
            }

            this.SelectedDepartmentName = this.SelectedDepartment.Name;
            this.WorkersInDepartment = new ObservableCollection<Worker>();

            foreach (var worker in workers.Where(w => w.Department != null && w.Department.Name == this.SelectedDepartment.Name))
            {
                this.WorkersInDepartment.Add(worker);
            }
        }

        /// <summary>
        /// Load values for selected supplier
        /// </summary>
        private void LoadValuesForSelectedSupplier()
        {
            this.SelectedSupplierName = this.selectedSupplier.Name;
            this.SelectedSupplierContact = this.selectedSupplier.Contact;
            this.SelectedSupplierAccNum = this.selectedSupplier.AccountNumber;
        }
    }
}
